<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-lx-calendar"></i>代理商管理</el-breadcrumb-item>
                <el-breadcrumb-item>代理商列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <!-- <div class="handle-box">
                <el-form :inline="true" ref="formQuery" :model="formQuery" class="demo-form-inline" label-width="100px">
                    <el-form-item label="代理商编号">
                        <el-input v-model="formQuery.id" placeholder="代理商编号"></el-input>
                    </el-form-item>
                    <el-form-item label="代理商名称">
                        <el-input v-model="formQuery.name" placeholder="代理商名称"></el-input>
                    </el-form-item>
                    <el-form-item label="创建时间">
                        <el-date-picker
                          v-model="formQuery.creatTime"
                          type="daterange"
                          align="right"
                          unlink-panels
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
                </el-form>
            </div> -->
            <div class="handle-box">
                <el-button type="primary" icon="delete" class="handle-del mr10" @click="handleAdd()">新增</el-button>
            </div>
            <el-table :data="tableData" border class="table" ref="multipleTable" @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
                <el-table-column prop="id" label="代理商编号" align="center" width="150">
                </el-table-column>
                <el-table-column prop="name" label="代理商名称" width="120" align="center">
                </el-table-column>
                <el-table-column prop="agentMobile" label="手机号" width="150" align="center">
                </el-table-column>
                <el-table-column prop="province" label="归属省" width="100" align="center">
                </el-table-column>
                <el-table-column prop="city" label="归属市" width="100" align="center">
                </el-table-column>
                <el-table-column prop="district" label="归属区" width="200" align="center">
                </el-table-column>
                <el-table-column prop="creatTime" :formatter="filterDate" label="创建时间" width="200" align="center">
                </el-table-column>
                <el-table-column
                  fixed="right"
                  label="操作"
                  width="100">
                  <template slot-scope="scope">
                    <el-button @click="handleQuery(scope.row)" type="text" size="small">查看</el-button>
                    <el-button @click="handleEdit(scope.row)" type="text" size="small">编辑</el-button>
                  </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination background @current-change="handleCurrentChange" layout="prev, pager, next" :total="pageData.total" :page-size="pageData.pageSize">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
    import moment from 'moment'

    export default {
        name: 'basetable',
        data() {
            return {
                url: './static/vuetable.json',
                tableData: [],
                multipleSelection: [],
                select_cate: '',
                select_word: '',
                del_list: [],
                is_search: false,
                addVisible:false,
                editVisible: false,
                delVisible: false,
                pageData: {
                    total: 0,
                    pageSize: 10,
                },
                formQuery: {
                    pageNo: 1,      // 当前页数
                },
            }
        },
        created() {
            // this.getData();
        },
        mounted() {
            this.getData();
        },
        computed: {
            // data() {
            //     return this.tableData.filter((d) => {
            //         let is_del = false;
            //         for (let i = 0; i < this.del_list.length; i++) {
            //             if (d.name === this.del_list[i].name) {
            //                 is_del = true;
            //                 break;
            //             }
            //         }
            //         if (!is_del) {
            //             return d;
            //         }
            //     })
            // }
        },
        methods: {
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            // 分页导航
            handleCurrentChange(val) {
                this.formQuery.pageNo = val;
                this.getData();
            },
            async getData() {   // 获取数据
                let res = await this.request('agentList', this.formQuery)
                this.tableData = res.data.list;
                this.pageData = {
                    total: res.data.total,
                    pageSize: res.data.pageSize
                }
            },
            filterDate(row, column) {
                let time = moment(row.creatTime).format('YYYY-MM-DD')
                return time;
            },
            handleAdd() {
                this.$router.push('/agentInfo?action=add');
            },
            handleQuery(val) {
                const record = val.id;
                this.$router.push(`/agentInfo?action=query&id=${record}`);
            },
            handleEdit(val) {
                const record = val.id;
                this.$router.push(`/agentInfo?action=edit&id=${record}`);
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
</style>
